from flask import Flask, request, jsonify
from sentence_transformers import SentenceTransformer
import numpy as np

app = Flask(__name__)
model = SentenceTransformer('/model/data/transformers/BAAI/bge-large-zh-v1.5')

# 定义一个用于获取文本嵌入的 API 路由
@app.route('/get_embedding', methods=['POST'])
def get_embedding():
    text = request.args.get('text')
    embedding = model.encode(text)
    # 将嵌入结果转换为列表
    embedding_list = embedding.tolist()
    return jsonify({'embedding': embedding_list})

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
